package com.ccp.dev.workflow.model.bpm;


import com.ccp.dev.core.util.BeanUtils;
import com.ccp.dev.workflow.bpmconst.BpmConst;

import java.util.HashMap;
import java.util.Map;

/**
 * 计算用户接口
 * @author jiayueqiao
 *
 */
public class CalcVars {
	
	public CalcVars(){
		
	}
	
	/**
	 * 构造函数
	 * @param startUserId		发起人ID
	 * @param preExecUserId		上一步执行人ID
	 * @param procInstId			流程实例ID
	 * @param vars				流程变量。
	 */
	public CalcVars(String startUserId, String preExecUserId, String procInstId, Map<String,Object> vars){
		this.startUserId=startUserId;
		this.prevExecUserId=preExecUserId;
		this.procInstId=procInstId;
		this.vars=vars;
	}
	/**
	 * 流程发起人
	 */
	private  String startUserId;
	/**
	 * 上一步执行人
	 */
	private String prevExecUserId;
	/**
	 * 流程实例Id
	 */
	private String procInstId;

	
	/**
	 * 流程变量
	 */
	private Map<String,Object> vars=new HashMap<String, Object>();

	public String getStartUserId() {
		return startUserId;
	}

	public void setStartUserId(String startUserId) {
		this.startUserId = startUserId;
	}

	public String getPrevExecUserId() {
		return prevExecUserId;
	}

	public void setPrevExecUserId(String prevExecUserId) {
		this.prevExecUserId = prevExecUserId;
	}

	public String getProcInstId() {
		return procInstId;
	}

	public void setProcInstId(String procInstId) {
		this.procInstId = procInstId;
	}

	

	public Map<String, Object> getVars() {
		return vars;
	}

	public void setVars(Map<String, Object> vars) {
		this.vars = vars;
	}
	
	/**
	 * 获取发起人所在的组织。
	 * @return
	 */
	public String getStartOrgId(){
		Object obj=getVariable(BpmConst.START_ORG_ID);
		if(BeanUtils.isEmpty(obj)){
			return "";
		}
		return obj.toString();
	}
	
	/**
	 * 获取上一步执人的组织。
	 * @return
	 */
	public String getPreStepOrgId(){
		Object obj=getVariable(BpmConst.PRE_ORG_ID);
		return obj.toString();
	}
	
	
	
	/**
	 * 获取流程变量。
	 * @param varName
	 * @return
	 */
	public Object getVariable(String varName){
		if(this.vars==null){
			return null;
		}
		if(!this.vars.containsKey(varName)){
			return null;
		}
		return this.vars.get(varName);
	}
	
};